package com.chat.demo.userservice;

import com.chat.demo.userservice.DTO.message.MessageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

// 私聊消息端口，到时候重构名称
@RestController
@RequestMapping("/messages")
public class Message_Controller {

    @Autowired
    private Message_Service messageService;

    // 发送消息
    @PostMapping("/send")
    public void sendMessage(
            @RequestParam Long senderId,
            @RequestParam Long receiverId,
            @RequestBody Map<String, String> payload) {

        String content = payload.get("content");
        messageService.sendMessage(senderId, receiverId, content);
    }

    // 更新消息状态
    @PostMapping("/update-status")
    public void updateStatus(
            @RequestParam Long messageId,
            @RequestParam String status) {

        messageService.updateMessageStatus(messageId, status);
    }

    // 查询私聊记录
    @GetMapping("/history")
    public List<MessageDTO> getChatHistory(
            @RequestParam Long userId1,
            @RequestParam Long userId2) {

        return messageService.getChatHistory(userId1, userId2);
    }
}